import 'package:flutter/material.dart';

/*
  点击改变组件状态
 */
void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "HomePager",
      home: Scaffold(
        appBar: AppBar(
          title: Text('HomePager'),
        ),
        body: HomePage(),
      ),
    );
  }
}

// 有状态控件
class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  bool _isShow = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        alignment: Alignment.center,  // 设置对齐方式后填充父控件
        color: Colors.grey[200],
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            children: [
              Visibility(
                  visible: _isShow,
                  child: Text('heheheheh')),
              IconButton(icon: Icon(Icons.refresh), onPressed: (){  // 点击回调
                setState(() {
                  _isShow = !_isShow;
                });
              })
            ],
          ),
        ),
      ),
    );
  }
}
